package Adapter;

public class Adapter {
    public static void main(String[] args) {
        // 创建一个Speaker对象
        Speaker speaker = new Speaker();

        // 使用适配器将Speaker转换为Translator
        Translator translator = new AdapterPattern(speaker);

        // 调用translate方法
        String result = translator.translate("你好");

        // 输出结果
        System.out.println(result);
    }
}

class Speaker {
    public String speak() {
        return "正在说话";
    }
}

interface Translator {
    String translate(String text);
}

class AdapterPattern implements Translator {
    private Speaker speaker;

    public AdapterPattern(Speaker speaker) {
        this.speaker = speaker;
    }

    @Override
    public String translate(String text) {
        return speaker.speak() + "并翻译: " + text;
    }
}
